<script setup>
  import {ElMessage} from "element-plus";
  import {ref} from "vue";
  import index from "vuex";

  const per=ref({
    name:'',salary:'',job:''
  });
  const lis=ref([

  ])
  const f1=()=>{
    if (per.value.name.trim()=='' ||per.value.salary.trim()=='' ||per.value.job.trim()==''){
      alert('请输入数据');
      return
    }
    lis.value.push(per.value)
    console.log(lis.value)
    per.value={
      name:'',salary: '',job:''
    }

  }
  const f2=(index,row)=>{
    if (confirm('您确定要删除'+row.name+'吗')){
      lis.value.splice(index,1)
      ElMessage.success('删除成功')
    }
  }
</script>

<template>
  <h1>员工列表综合练习</h1>
  <el-form label-width="80" style="width: 800px;margin: 0 auto">
    <el-form-item label="姓名">
      <el-input v-model="per.name"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input v-model="per.salary"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input v-model="per.job"></el-input>
    </el-form-item>
    <el-form>
      <el-button @click="f1" type="success">提交</el-button>
    </el-form>
  </el-form>
  <br>
  <el-table :data="lis" style="width: 800px;margin: 0 auto">
    <el-table-column label="编号" type="index" width="80" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name" align="center"></el-table-column>
    <el-table-column label="工资" prop="salary" align="center"></el-table-column>
    <el-table-column label="岗位" prop="job" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <template  #default="scope">
        <el-button type="danger" @click="f2(scope.$index,scope.row)">
          删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>

</template>

<style scoped>

</style>